package com.hr.zhxy.test.controller;

import java.util.Arrays;
import java.util.Map;

import com.hr.zhxy.test.feign.AttendanceFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hr.zhxy.test.entity.LevelEntity;
import com.hr.zhxy.test.service.LevelService;
import com.hr.zhxy.common.utils.PageUtils;
import com.hr.zhxy.common.utils.R;


/**
 * @author wzh
 * @email sunlightcs@gmail.com
 * @date 2022-01-17 17:10:00
 */
@RestController
@RequestMapping("test/level")
@Api("测试")
public class LevelController {
    @Autowired
    private LevelService levelService;

    @Autowired
    AttendanceFeign attendanceFeign;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = levelService.queryPage(params);

        return R.ok().put("page", page);
    }

    @GetMapping("/p1")
    @ApiOperation("测试接口")
    public String test() {
        return attendanceFeign.getP1();
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{levelId}")
    public R info(@PathVariable("levelId") Integer levelId) {
        LevelEntity level = levelService.getById(levelId);

        return R.ok().put("level", level);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody LevelEntity level) {
        levelService.save(level);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody LevelEntity level) {
        levelService.updateById(level);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] levelIds) {
        levelService.removeByIds(Arrays.asList(levelIds));

        return R.ok();
    }

}
